package luj.tool.jnproxyan.proxy.admin.http.render;

import org.springframework.stereotype.Component;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class TimeValueRenderer {

  public String render(Number value) {
    long milli = value.longValue();
    if (milli < 0) {
      return "-";
    }
    return render(ZonedDateTime.ofInstant(Instant.ofEpochMilli(milli), ZoneId.systemDefault()));
  }

  public String render(ZonedDateTime time) {
    return time.format(TIME_FMT);
  }

  private static final DateTimeFormatter TIME_FMT = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
}
